
#ifndef _DATABBASE_OPERATION_
#define _DATABBASE_OPERATION_

#include <stddef.h>

#ifndef _YACC_TAB_HEADER_
#define _YACC_TAB_HEADER_
#include "y.tab.h"
#endif


enum STRUCT{
    TABLELIST,
};
enum Type{FIELD_INT,FIELD_CHAR,FIELD_FLOAT};
enum EXECEUTERROR{
    CONFIG_FILE_OPEN_ERROR,
    CREATE_DATABASE_ERROR,
    DATABASE_NOT_EXIST_ERROR,
    CONFIG_TABLE_CREATE_ERROR};


typedef struct CreateField{
    char * name;
    enum Type type;
    int  length;
    struct CreateField * next;
}CreateFieldStruct,* CreateFieldStructPoint;

typedef struct Create{
    char * name;
    CreateFieldStructPoint fileds;
}CreateStruct,*CreateStructPoint;


typedef struct TableList{
    char name[128];
    struct TableList * next;
}TableListStruct,*TableListStructPoint;

typedef struct DatabaseConfig{
    char * configPath;
    char * m_dataPath;
    int tabLength;
}DatabaseConfigStruct, * DatabaseConfigStructPoint;

char * m_dataPath = NULL;
char * configPath = NULL;
char * m_usingDatabase = NULL;
TableListStructPoint tlsp = NULL;
DatabaseConfigStructPoint m_databaseConfig = NULL;


char * strpathcat(char * prefix,char * other);

//Get the database config;
void initDatabase();

void _exitDatabase();
void freeGlobalVariable();

//Error handle;
void handleError(enum EXECEUTERROR error,void * data);
//Read table list from database.
TableListStructPoint readTableList();
void freeStruct(enum STRUCT type,void * root);
//Write back table list.
void writebackTableList(); 

int calTabCnt(int max);
void borderPrint(int cnt);
void contentPrint(char * res,int cnt);

//Sql execution enterance.
void executeSQL(void * syntaxTree,int type);


//Create database dbname;
void createDatabase(char * dbname);
//Show database;
void showDatabase();

//Show tables;
void showTables();

#endif